package com.xomily.devops.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xomily.common.annotation.Log;
import com.xomily.common.core.controller.BaseController;
import com.xomily.common.core.domain.AjaxResult;
import com.xomily.common.enums.BusinessType;
import com.xomily.devops.domain.DevHost;
import com.xomily.devops.service.IDevHostService;
import com.xomily.common.utils.poi.ExcelUtil;
import com.xomily.common.core.page.TableDataInfo;


/**
 * 主机信息Controller
 * 
 * @author xomily
 * @date 2021-11-29
 */
@RestController
@RequestMapping("/devops/host")
public class DevHostController extends BaseController
{
    @Autowired
    private IDevHostService devHostService;

    /**
     * 查询主机信息列表
     */
    @PreAuthorize("@ss.hasPermi('devops:host:list')")
    @GetMapping("/list")
    public TableDataInfo list(DevHost devHost)
    {
        startPage();
        List<DevHost> list = devHostService.selectDevHostList(devHost);
        return getDataTable(list);
    }

    /**
     * 导出主机信息列表
     */
    @PreAuthorize("@ss.hasPermi('devops:host:export')")
    @Log(title = "主机信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DevHost devHost)
    {
        List<DevHost> list = devHostService.selectDevHostList(devHost);
        ExcelUtil<DevHost> util = new ExcelUtil<DevHost>(DevHost.class);
        return util.exportExcel(list, "主机信息数据");
    }

    /**
     * 获取主机信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('devops:host:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(devHostService.selectDevHostById(id));
    }

    /**
     * 获取主机信息详情
     */
    @PreAuthorize("@ss.hasPermi('devops:host:query')")
    @GetMapping(value = "detail/{id}")
    public AjaxResult getDetail(@PathVariable("id") Long id)
    {
        return AjaxResult.success(devHostService.selectDevHostDetailById(id));
    }
    
    /**
     * 新增主机信息
     */
    @PreAuthorize("@ss.hasPermi('devops:host:add')")
    @Log(title = "主机信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DevHost devHost)
    {
        return toAjax(devHostService.insertDevHost(devHost));
    }

    /**
     * 修改主机信息
     */
    @PreAuthorize("@ss.hasPermi('devops:host:edit')")
    @Log(title = "主机信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DevHost devHost)
    {
        return toAjax(devHostService.updateDevHost(devHost));
    }

    /**
     * 状态修改
     */
    @PreAuthorize("@ss.hasPermi('devops:host:edit')")
    @Log(title = "主机信息", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody DevHost host)
    {
        host.setUpdateBy(getUsername());
        return toAjax(devHostService.updateDevHostStatus(host));
    }
    
    
    /**
     * 删除主机信息
     */
    @PreAuthorize("@ss.hasPermi('devops:host:remove')")
    @Log(title = "主机信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(devHostService.deleteDevHostByIds(ids));
    }
}
